package com.csgc.camera.biz.other.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.csgc.camera.constants.MaskConfig
import com.csgc.camera.constants.MaskDateStyle

import com.csgc.camera.events.MaskDataStyleEvent
import com.csgc.camera.util.TimeUtil
import com.csgc.camera.util.clickWithTrigger
import com.cysd.spsyxj.databinding.ItemMaskDateStyleBinding

import com.drake.channel.sendEvent

class MaskDateStyleAdapter(val context:Context):Adapter<MaskDateStyleAdapter.MaskDateStyleHolder>() {

    private val time:Long by lazy {
        System.currentTimeMillis()
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MaskDateStyleHolder {
        return MaskDateStyleHolder(ItemMaskDateStyleBinding.inflate(LayoutInflater.from(context),parent,false))
    }

    override fun onBindViewHolder(holder: MaskDateStyleHolder, position: Int) {
        holder.binding.apply {

            val style = when(position){
                0->{
                    MaskDateStyle.DateWeekTime.pattern
                }
                1->{
                    MaskDateStyle.DateFullTime.pattern
                }
                2->{
                    MaskDateStyle.DateTime.pattern
                }
                3->{
                    MaskDateStyle.DateWeek.pattern
                }
                4->{
                    MaskDateStyle.WeekTime.pattern
                }
                5->{
                    MaskDateStyle.Week.pattern
                }
                6->{
                    MaskDateStyle.Time.pattern
                }

                else -> {MaskDateStyle.DateWeek.pattern}
            }

            tvDateStyle.text = TimeUtil.getTimeFormat(time,style)
            if (style == MaskConfig.maskDateStyle){
                ivChecked.visibility = View.VISIBLE
            }else{
                ivChecked.visibility = View.GONE
            }

            root.clickWithTrigger {
                MaskConfig.maskDateStyle = style
                notifyDataSetChanged()
                sendEvent(MaskDataStyleEvent(pattern = style))

            }

        }
    }

    override fun getItemCount(): Int {
        return 7
    }

    inner class MaskDateStyleHolder(val binding:ItemMaskDateStyleBinding):ViewHolder(binding.root)
}